package puzzle.nurikabe.data;

public class StateUtil {
	public static final int OUT_OF_BOARD = -0x10000000;
	public static final int UNDETERMINED_SHIMA_BASE = 0x10000000;

	public static boolean isRealKabe(int n) {
		return n < 0 && n != OUT_OF_BOARD;
	}

	public static boolean isKabe(int n) {
		return n < 0;
	}

	public static boolean isDeterminedShima(int n) {
		return n > 0 && n < UNDETERMINED_SHIMA_BASE;
	}

	public static boolean isUndeterminedShima(int n) {
		return n >= UNDETERMINED_SHIMA_BASE;
	}

	public static int encodeOwningShima(int n, int i) {
		assert (n >= UNDETERMINED_SHIMA_BASE)
				&& ((n & 0x0fff0000) == 0 || (n & 0x0fff0000) == (i << 16));
		return n | (i << 16);
	}

	public static int decodeOwningShima(int n) {
		if (isDeterminedShima(n)) {
			return n;
		} else if (isUndeterminedShima(n)) {
			return (n & 0x0fff0000) >> 16;
		} else {
			return 0;
		}
	}

}
